package com.kirk.crawler.core.loader;

import com.kirk.crawler.constant.SystemConstants;

import java.net.MalformedURLException;
import java.net.URL;


/**
 *  <p> ResouceLoader.java </p>
 *
 * @Author      kirkliu
 * @Date        2020-08-29 22:23
 * @version     1.0.0
 * @Description 资源帮助类
 */
public class ResouceLoader {

	/**
	 * 根据文件路径，获取URL对象
	 * @param url_name 文件全路径
	 * @return URL
	 */
	public static URL getFileURL(String url_name) {
		try {
			return new URL(SystemConstants.PROTOCOL_FILE + url_name);
		} catch (MalformedURLException e) {
			e.printStackTrace();
			throw new RuntimeException("Malformed URL " + url_name, e);
		}
	}

	public static String getFilePath(String filePath) {
		return getFileURL(filePath).getPath();
	}


	public static URL getResouce(String url_name) {
		//return getFileURL(url_name);
		return ClassLoader.getSystemResource(url_name);
	}

}
